<?php 

include_once("includes/config.php");
require("includes/mod_function.inc.php");

global $TOP_CONTENT_CATEGORY_SID,$TOP_AREA_CATEGORY_SID ;
global $foxydb;

$fs = new FoxySite();

$purl = $_REQUEST['url'];
$pattern = "/[\?&](.*)/i";
$replacement = "";
$purl = preg_replace($pattern, $replacement, $purl);

$ptagsid = $_REQUEST['tagsid'];
if($purl){
	$ret = $fs->getRelatedLinksByUrl($purl,60,10,1);
	$links = $ret['link'];
	$foxydb->open();
	$tags = $foxydb->selectHotTagsByUrl($purl,10);
	$foxydb->close();
}else if ($ptagsid){
	$foxydb->open();
	$hotLinks = $foxydb->selectHotLinksByTagSid($ptagsid,100);
	if(!$hotLinks || count($hotLinks)==0) $hotLinks = $foxydb->selectHotLinks(100);
	$hotTags = $foxydb->selectHotTagsByTagsid($ptagsid,10);
	if(!$hotTags || count($hotTags)==0) $hotTags = $foxydb->selectHotTags(10);
	$foxydb->close();
}else {
	$foxydb->open();
	$hotLinks = $foxydb->selectHotLinks(100);
	$hotTags = $foxydb->selectHotTags(10);
	$foxydb->close();
}

include_once("includes/header.php");
?>
  <TABLE width="100%" cellpadding=2 cellspacing=0 border=1>
  <TR><TD colspan='2' align=right><?php include_once("includes/menu.php");?></TD></TR>
  <?php if ($purl && $links && count($links)>0){?>
	  <TR>
		<TD ><A href='<?php echo $links[0][1]?>' target='_blank'><b><?php echo $links[0][2]?></b></A>&nbsp;&nbsp;相关文章<br/><?php echo $links[0][3]?></TD>
	  </TR>
	  <TR>
		<TD >标签：
		<?php foreach($tags as $tag){?>
		<A href='linklist.php?tagsid=<?php echo $tag['sid']?>' target='_blank'><b><?php echo $tag['name'];?></b></A>&nbsp;&nbsp;
		<?php }?>
		</TD>
	  </TR>

	  <?php for($i=1;$i<count($links);$i++){
		  $ln = $links[$i];
	  ?>
		  <TR>
			<TD valign="top"><A href="<?php echo $ln[1];?>" target='_blank'><?php echo $ln[2];?></A>&nbsp;&nbsp;<?php echo $ln[3];?></TD>
		  </TR>
	  <?php }
	}else if ($hotLinks && count($hotLinks)>0){
	?>

	  <TR>
		<TD >热门标签：
		<?php foreach($hotTags as $tag){?>
		<A href='linklist.php?tagsid=<?php echo $tag['sid']?>'><b><?php echo $tag['name'];?></b></A>&nbsp;&nbsp;
		<?php }?>
		</TD>
	  </TR>
	<?php
		foreach($hotLinks as $link){
	?>		
		  <TR>
			<TD valign="top"><A href="<?php echo $link['url'];?>" target='_blank'><?php echo $link['name'];?></A>&nbsp;&nbsp;<?php echo $link['description'];?></TD>
		  </TR>		
	<?php } 
	}?>

  </TABLE>


<?php include("includes/footer.php");?>